<?php
$data = array();
readFolder('folder', $data);
echo '<pre>';
print_r($data);

function readFolder($path, &$result){
    $path = utf8_decode($path);
    $handle = opendir($path);
    $path	= rtrim($path, '/') . '/';

    while ($item = readdir($handle)){
        // check if there's a folder
        if (substr($item, 0, 1) != '.' && is_dir($path . $item)){
            $result[$item] = array(
                "type" => "folder",
                "items" => null
            );

            readFolder($path . $item, $result[$item]["items"]);
        }
        
        // check if there's a file
        if (substr($item, 0, 1) != '.' && is_file($path . $item)){
            $result[$item] = array(
                "type" => "file",
                "items" => null
            );
        }
    }
    closedir($handle);

   // return !count($result) ? false : $result;
}
